<?php
	class Search extends MY_Controller{
	    public function __construct(){
		   parent::__construct();
		   $this->load->helper("url");
		   $this->load->model("model_search");
		   $this->load->library("pager");
	    }
		public function index(){
			if(!$_GET){die();}
			$title   = $this->fillter($this->input->get("keywords"));
			$type = $this->fillter($this->input->get("tour_type"));
			$start = strtotime($this->input->get("start_date"));
			$price  = $this->fillter($this->input->get("price"));
			switch($price){
				case "1" : $pri = "BETWEEN 50 AND 100"; break;
				case "2" : $pri = "BETWEEN 100 AND 300"; break;
				case "3" : $pri = "BETWEEN 300 AND 500"; break;
				case "4" : $pri = "BETWEEN 500 AND 1000"; break;
				case "5" : $pri = "BETWEEN 1000 AND 1500"; break;
				case "6" : $pri = "BETWEEN 1500 AND 3000"; break;
				case "7" : $pri = "> 3000"; break;
				default  : $pri = "> 0"; break;
			}
			$limit = 6;
			$start = $this->pager->start();
			$total = $this->model_search->count_all_search($title,$type,$pri);
		    $pages = $this->pager->page($total,$limit);
			$data['travel']   	= $title;
			$data['travel_type']   	= $type;
			$data['start_date']   	= $start;
			$data['price']   	= $price;
			$data['listpage']  = $this->pager->listpages($pages,$start,$limit,$title,$type,$price);
			$data['config']    = $this->config();
			$data['total'] 	   = $total; 
			$data['results'] = $this->model_search->search($title,$type,$pri,$limit,$start);
			$data['title'] 	   = "Search results";
			switch($type){
				case "1" : $this->load->view("search/layout",$data);  break;
				case "2" : $this->load->view("search/cruises/layout",$data); break;
				case "3" : $this->load->view("search/packge/layout",$data); break;
				default  : die("false!"); break;
			}
			//$this->debug($data['results']);
		}		
		public function tours(){
			if(!$_GET){die();}
			$keyword   = $this->fillter($this->input->get("keyword"));
			$limit = 6;
			$start = $this->pager->start();
			$total = $this->model_search->count_tours($keyword);
		    $pages = $this->pager->page($total,$limit);
			$data['listpage']  = $this->pager->listpage($pages,$start,$limit,$keyword);
			$data['config']    = $this->config();
			$data['total'] 	   = $total; 
			$data['results'] = $this->model_search->all_tours($keyword,$limit,$start);
			$data['title'] 	   = "Search results";
			$this->load->view("search/alltours/layout",$data);
		}
	}